﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MashGen.Engine.Expressions
{
    public class Power : AbstractExpression
    {
        public AbstractExpression Radix { get; private set; }
        public AbstractExpression Exponent { get; private set; }

        public Power(AbstractExpression radix, AbstractExpression exponent)
        {
            if (radix == null)
            {
                throw new ArgumentNullException("radix");
            }
            if (exponent == null)
            {
                throw new ArgumentNullException("exponent");
            }
            Radix = radix;
            Exponent = exponent;
        }

        public override R Vist<R, P>(IExpressionVisitor<R, P> visitor, P parameter = default(P))
        {
            return visitor.VistPower(this, parameter);
        }

        public override int GetHashCode()
        {
            return 13 * Radix.GetHashCode() + Exponent.GetHashCode();
        }

        public override bool Equals(AbstractExpression other)
        {
            var otherPower = other as Power;
            if (ReferenceEquals(otherPower, null))
            {
                return false;
            }
            return Radix.Equals(otherPower.Radix) 
                && Exponent.Equals(otherPower.Exponent);
        }
    }
}
